home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb-4.5 / dist / gdb / altos-xdep.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-03  |  4.3 KB  |  166 lines

  1. /* Low level interface to ptrace, for GDB when running under m68k SVR2 Unix
  2.    on Altos 3068.  Report bugs to Jyrki Kuoppala <jkp@cs.hut.fi>
  3.    Copyright (C) 1989, 1991 Free Software Foundation, Inc.
  4.  
  5. This file is part of GDB.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #include "defs.h"
  22. #include "frame.h"
  23. #include "inferior.h"
  24.  
  25. #ifdef USG
  26. #include <sys/types.h>
  27. #endif
  28.  
  29. #include <sys/param.h>
  30. #include <sys/dir.h>
  31. #include <signal.h>
  32. #include <sys/ioctl.h>
  33. #include <fcntl.h>
  34. #ifdef USG
  35. #include <sys/page.h>
  36. #ifdef ALTOS
  37. #include <sys/net.h>
  38. #include <errno.h>
  39. #endif
  40. #endif
  41.  
  42. #include "gdbcore.h"
  43. #include <sys/user.h>        /* After a.out.h  */
  44. #include <sys/file.h>
  45. #include <sys/stat.h>
  46.  
  47.  
  48. /* Work with core dump and executable files, for GDB. 
  49.    This code would be in core.c if it weren't machine-dependent. */
  50.  
  51. void
  52. core_file_command (filename, from_tty)
  53.      char *filename;
  54.      int from_tty;
  55. {
  56.   int val;
  57.   extern char registers[];
  58.  
  59.   /* Discard all vestiges of any previous core file
  60.      and mark data and stack spaces as empty.  */
  61.  
  62.   if (corefile)
  63.     free (corefile);
  64.   corefile = 0;
  65.  
  66.   if (corechan >= 0)
  67.     close (corechan);
  68.   corechan = -1;
  69.  
  70.   data_start = 0;
  71.   data_end = 0;
  72.   stack_start = STACK_END_ADDR;
  73.   stack_end = STACK_END_ADDR;
  74.  
  75.   /* Now, if a new core file was specified, open it and digest it.  */
  76.  
  77.   if (filename)
  78.     {
  79.       filename = tilde_expand (filename);
  80.       make_cleanup (free, filename);
  81.       
  82.       if (have_inferior_p ())
  83.     error ("To look at a core file, you must kill the inferior with \"kill\".");
  84.       corechan = open (filename, O_RDONLY, 0);
  85.       if (corechan < 0)
  86.     perror_with_name (filename);
  87.       /* 4.2-style (and perhaps also sysV-style) core dump file.  */
  88.       {
  89.     struct user u;
  90.  
  91.     unsigned int reg_offset;
  92.  
  93.     val = myread (corechan, &u, sizeof u);
  94.     if (val < 0)
  95.       perror_with_name ("Not a core file: reading upage");
  96.     if (val != sizeof u)
  97.       error ("Not a core file: could only read %d bytes", val);
  98.     data_start = exec_data_start;
  99.  
  100. #if !defined (NBPG)
  101. #define NBPG NBPP
  102. #endif
  103. #if !defined (UPAGES)
  104. #define UPAGES USIZE
  105. #endif
  106.  
  107.     data_end = data_start + NBPG * u.u_dsize;
  108.     stack_start = stack_end - NBPG * u.u_ssize;
  109.     data_offset = NBPG * UPAGES + exec_data_start % NBPG /* Not sure about this //jkp */;
  110.     stack_offset = NBPG * (UPAGES + u.u_dsize);
  111.  
  112.     /* Some machines put an absolute address in here and some put
  113.        the offset in the upage of the regs.  */
  114.     reg_offset = (int) u.u_state;
  115.     if (reg_offset > NBPG * UPAGES)
  116.       reg_offset -= KERNEL_U_ADDR;
  117.  
  118.     bcopy (&u.u_exdata, &core_aouthdr, sizeof (AOUTHDR));
  119.     printf ("Core file is from \"%s\".\n", u.u_comm);
  120.  
  121.     /* I don't know where to find this info.
  122.        So, for now, mark it as not available.  */
  123.     N_SET_MAGIC (core_aouthdr, 0);
  124.  
  125.     /* Read the register values out of the core file and store
  126.        them where `read_register' will find them.  */
  127.  
  128.     {
  129.       register int regno;
  130.  
  131.       for (regno = 0; regno < NUM_REGS; regno++)
  132.         {
  133.           char buf[MAX_REGISTER_RAW_SIZE];
  134.  
  135.           val = lseek (corechan, register_addr (regno, reg_offset), 0);
  136.           if (val < 0
  137.           || (val = myread (corechan, buf, sizeof buf)) < 0)
  138.         {
  139.           char * buffer = (char *) alloca (strlen (reg_names[regno])
  140.                            + 30);
  141.           strcpy (buffer, "Reading register ");
  142.           strcat (buffer, reg_names[regno]);
  143.                            
  144.           perror_with_name (buffer);
  145.         }
  146.  
  147.           supply_register (regno, buf);
  148.         }
  149.     }
  150.       }
  151.       if (filename[0] == '/')
  152.     corefile = savestring (filename, strlen (filename));
  153.       else
  154.     {
  155.       corefile = concat (current_directory, "/", filename, NULL);
  156.     }
  157.  
  158.       set_current_frame ( create_new_frame (read_register (FP_REGNUM),
  159.                         read_pc ()));
  160.       select_frame (get_current_frame (), 0);
  161.       validate_files ();
  162.     }
  163.   else if (from_tty)
  164.     printf ("No core file now.\n");
  165. }
  166.